var game_info;
var result;

function init()
{
    game_info = window.arguments[0];
    result = window.arguments[1];

    document.getElementById("game_name").value = game_info.name;
    if (game_info.path != undefined) document.getElementById("game_path").value = game_info.path;
    if (game_info.args != undefined) document.getElementById("game_args").value = game_info.args;
}

function browseFile()
{
    const filePicker = Components.classes['@mozilla.org/filepicker;1'].createInstance(Components.interfaces.nsIFilePicker);

    filePicker.init(window, "ゲームがインストールされている場所を指定してください。", Components.interfaces.nsIFilePicker.modeOpen);
    filePicker.defaultString = "";
    var res = filePicker.show();
    switch (res) {
        case Components.interfaces.nsIFilePicker.returnOK:
            document.getElementById("game_path").value = filePicker.file.path;
            break;
        default:
            break;
    }
}

function saveChanges()
{
    var name = document.getElementById("game_name").value;
    var path = document.getElementById("game_path").value;
    var args = document.getElementById("game_args").value;

    if (name.length < 2) {
        alert('ゲームタイトルを入力してください');
        return false;
    }

    result.protocol = game_info.protocol;
    result.name = name;
    result.path = path;
    result.args = args;

    return true;
}